test: cmocka: Remove legacy unit tests#10615
Conversation
There was a problem hiding this comment.
Pull request overview
Removes legacy CMocka-based math unit tests in favor of the Ztest equivalents, and adds missing Ztest coverage for crc32().
Changes:
- Removed CMocka arithmetic (
numbers/) and trigonometry (trig/) test sources and their CMake entries - Moved trigonometry test constants (tolerances) into the Ztest
trig_test.cand adjustedtrig_tables.haccordingly - Added a new Ztest file covering
crc32()and wired it into the arithmetic test CMake target
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/ztest/unit/math/basic/trigonometry/trig_test.c | Moves comparison tolerances into the Ztest trig test file |
| test/ztest/unit/math/basic/trigonometry/trig_tables.h | Keeps reference tables for trig tests after legacy test removal/move |
| test/ztest/unit/math/basic/arithmetic/test_norm_int32_ztest.c | Adds provenance comments for ported tests |
| test/ztest/unit/math/basic/arithmetic/test_gcd_ztest.c | Adds provenance comments for ported tests |
| test/ztest/unit/math/basic/arithmetic/test_find_min_int16_ztest.c | Adds provenance comments for ported tests |
| test/ztest/unit/math/basic/arithmetic/test_find_max_abs_int32_ztest.c | Adds provenance comments for ported tests |
| test/ztest/unit/math/basic/arithmetic/test_find_equal_int16_ztest.c | Adds provenance comments for ported tests |
| test/ztest/unit/math/basic/arithmetic/test_crc32_ztest.c | Adds new Ztest coverage for crc32() |
| test/ztest/unit/math/basic/arithmetic/test_ceil_divide_ztest.c | Adds provenance comments for ported tests |
| test/ztest/unit/math/basic/arithmetic/CMakeLists.txt | Registers the new crc32 Ztest source |
| test/cmocka/src/math/trig/sin_32b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/sin_16b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/lut_sin_16b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/cos_32b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/cos_16b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/asin_32b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/asin_16b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/acos_32b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/acos_16b_fixed.c | Removes legacy CMocka trig test |
| test/cmocka/src/math/trig/CMakeLists.txt | Removes CMocka trig test targets |
| test/cmocka/src/math/numbers/norm_int32.c | Removes legacy CMocka numbers test |
| test/cmocka/src/math/numbers/gcd.c | Removes legacy CMocka numbers test |
| test/cmocka/src/math/numbers/find_min_int16.c | Removes legacy CMocka numbers test |
| test/cmocka/src/math/numbers/find_max_abs_int32.c | Removes legacy CMocka numbers test |
| test/cmocka/src/math/numbers/find_equal_int16.c | Removes legacy CMocka numbers test |
| test/cmocka/src/math/numbers/ceil_divide.c | Removes legacy CMocka numbers test |
| test/cmocka/src/math/numbers/CMakeLists.txt | Removes CMocka numbers test targets |
| test/cmocka/src/math/CMakeLists.txt | Stops including removed CMocka subdirectories |
| test/cmocka/include/trig_tables.h | Removes legacy CMocka trig tables header |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2025 Intel Corporation. All rights reserved. | ||
| * Copyright(c) 2021 Intel Corporation. All rights reserved. | ||
| * | ||
| * Author: Shriram Shastry <malladi.sastry@linux.intel.com> | ||
| */ | ||
|
|
||
| #ifndef __SOF_ZTEST_TRIG_TABLES_H__ | ||
| #define __SOF_ZTEST_TRIG_TABLES_H__ | ||
|
|
||
| /* Reference table generated by sin(), gcc-4.3.2 */ | ||
| static const float sin_ref_table[] = { |
There was a problem hiding this comment.
The include guard was removed from trig_tables.h. If this header gets included more than once in the same translation unit (directly or indirectly), it will cause redefinition errors for the static const tables. Reintroduce an include guard (or #pragma once) around the header contents.
| /* Define M_PI if not available */ | ||
| #ifndef M_PI | ||
| #define M_PI 3.14159265358979323846 | ||
| #define M_PI 3.14159265358979323846 |
There was a problem hiding this comment.
These new #define lines use tab alignment, which is easy to drift and often conflicts with C style guidelines/formatters. Prefer a single space after the macro name (or project-standard formatting) to keep the header/test consistently formatted and formatter-friendly.
| #define DEGREES_TO_RADIANS 0.017453292519943295 | ||
|
|
||
| #define CMP_TOLERANCE_32B 0.0000000611175871f | ||
| #define CMP_TOLERANCE_16B 0.000065f | ||
| #define CMP_TOLERANCE_ASIN_32B 0.000000068141916f | ||
| #define CMP_TOLERANCE_ACOS_32B 0.000000060077032f | ||
| #define CMP_TOLERANCE_ASIN_16B 0.0001152158f | ||
| #define CMP_TOLERANCE_ACOS_16B 0.0001196862f | ||
| #define CMP_TOLERANCE_SIN 3.1e-5f |
There was a problem hiding this comment.
These new #define lines use tab alignment, which is easy to drift and often conflicts with C style guidelines/formatters. Prefer a single space after the macro name (or project-standard formatting) to keep the header/test consistently formatted and formatter-friendly.
| // generative artificial intelligence solutions. | ||
| // | ||
| // Converted from CMock to Ztest | ||
| // Original file: sof/test/cmocka/src/math/numbers/ceil_divide.c |
There was a problem hiding this comment.
The provenance comment format/path here differs from the other converted tests (e.g., "Original tests from test/cmocka/..." vs "Original file: sof/test/cmocka/..."). Standardizing the phrasing and path prefix across these Ztest ports will make future test archaeology and bulk updates easier.
| // Original file: sof/test/cmocka/src/math/numbers/ceil_divide.c | |
| // Original tests from test/cmocka/src/math/numbers/ceil_divide.c |
lgirdwood
left a comment
There was a problem hiding this comment.
Long term we need to figure out how to do memory profiling like valgrind using Zephyr, maybe this would be a x86 Zephyr target running under valgrind.
This patch removes tests that have been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for number.c - lines: 80.4 % (45/56) - funcs: 83.3 % (5/6) - branches: 78.1 % (25/32) Ztest stats for number.c - lines: 83.6 % (46/55) - funcs: 83.3 % (5/6) - branches: 78.9 % (30/38) Additionally, information about the source of the original code and its author has been added to the new version of tests. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
This patch removes tests that have been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for number.c - lines: 80.4 % (45/56) - funcs: 83.3 % (5/6) - branches: 78.1 % (25/32) Ztest stats for number.c - lines: 83.6 % (46/55) - funcs: 83.3 % (5/6) - branches: 78.9 % (30/38) Additionally, information about the source of the original code and its author has been added to the new version of tests. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
This patch removes tests that have been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for number.c - lines: 80.4 % (45/56) - funcs: 83.3 % (5/6) - branches: 78.1 % (25/32) Ztest stats for number.c - lines: 83.6 % (46/55) - funcs: 83.3 % (5/6) - branches: 78.9 % (30/38) Additionally, information about the source of the original code and its author has been added to the new version of tests. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
This patch removes tests that have been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for number.c - lines: 80.4 % (45/56) - funcs: 83.3 % (5/6) - branches: 78.1 % (25/32) Ztest stats for number.c - lines: 83.6 % (46/55) - funcs: 83.3 % (5/6) - branches: 78.9 % (30/38) Additionally, information about the source of the original code and its author has been added to the new version of tests. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
This patch removes tests that have been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for number.c - lines: 80.4 % (45/56) - funcs: 83.3 % (5/6) - branches: 78.1 % (25/32) Ztest stats for number.c - lines: 83.6 % (46/55) - funcs: 83.3 % (5/6) - branches: 78.9 % (30/38) Additionally, information about the source of the original code and its author has been added to the new version of tests. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
This patch removes tests that have been successfully converted to the new framework (from cmock to ztest). Code coverage testing did not reveal any regression. CMock stats for number.c - lines: 80.4 % (45/56) - funcs: 83.3 % (5/6) - branches: 78.1 % (25/32) Ztest stats for number.c - lines: 83.6 % (46/55) - funcs: 83.3 % (5/6) - branches: 78.9 % (30/38) These were the last tests from this group and together with them I'm removing the remaining references in the build system. Additionally, information about the source of the original code and its author has been added to the new version of tests. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Coverage analysis showed crc32 in src/math/numbers.c was not exercised by either the CMock or the Ztest arithmetic test suites. Add test_crc32_ztest.c to the sof.unit.math.basic.arithmetic suite with six test cases covering all meaningful code paths: - empty buffer (zero-iteration outer loop) - single 0x00 byte (inner loop, XOR-with-polynomial branch taken) - single 0xFF byte (inner loop, shift-only branch taken) - standard check vector "123456789" → 0xCBF43926 (ISO 3309 / ITU-T V.42) - non-zero base value (different initial CRC register, verifies chaining) - four-byte all-zeros buffer (multiple outer-loop iterations) Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
The ztest trigonometry suite had a local copy of test/cmocka/include/trig_tables.h. This was a mistake: when the legacy CMock tests are eventually removed, the original header will disappear losing git history. Fix this by: - Deleting the duplicate trig_tables.h from the ztest directory - Adding test/cmocka/include to the CMakeLists include path so the ztest suite references the single source-of-truth header directly - Moving tolerance constants that were defined in the local copy into trig_test.c, where they are actually used With this change, any future rename or move of the CMock header will be handled in one place and the ztest suite will follow automatically. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
All nine CMock trigonometry tests have been ported to Ztest in
test/ztest/unit/math/basic/trigonometry. Remove the now-redundant CMock
suite.
Changes:
- Delete test/cmocka/src/math/trig/ and all its test files:
acos_16b_fixed.c, acos_32b_fixed.c
asin_16b_fixed.c, asin_32b_fixed.c
cos_16b_fixed.c, cos_32b_fixed.c
sin_16b_fixed.c, sin_32b_fixed.c
lut_sin_16b_fixed.c
- Remove the trig subdirectory entry from
test/cmocka/src/math/CMakeLists.txt
- Move test/cmocka/include/trig_tables.h to the ztest trigonometry
directory as a git rename, so the full file history is preserved
and the ztest suite owns it going forward
Coverage analysis (native_sim, Twister vs. unit_test_defconfig):
CMock stats for trig.c:
- lines: 92.9 % (92/99)
- funcs: 75.0 % (3/4)
- branches: 76.5 % (26/34)
Ztest stats for trig.c:
- lines: 96.6 % (86/89)
- funcs: 100.0 % (4/4)
- branches: 89.6 % (43/48)
CMock stats for lut_trig.c:
- lines: 100.0 % (26/26)
- funcs: 100.0 % (1/1)
- branches: 100.0 % (12/12)
Ztest stats for lut_trig.c:
- lines: 100.0 % (17/17)
- funcs: 100.0 % (2/2)
- branches: 100.0 % (4/4)
Notable improvements in the Ztest suite:
- cmpx_cexp() was never called by CMock (0 calls); Ztest reaches it
1002 times, raising trig.c function coverage from 75 % to 100 %
- lut_sin_16b_fixed test now exercises sofm_sine_lookup_16b() in
addition to sofm_lut_sin_fixed_16b(), covering both functions in
lut_trig.c vs. only one in CMock
The previous commit that added test/cmocka/include to the ztest include
path is superseded: trig_tables.h now lives alongside the tests that
use it, so no out-of-tree include directory is needed.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Remove the legacy arithmetic and trigonometry CMock unit test versions. Also adds a missing test for crc32() which was uncovered in both frameworks.
All ported test cases pass on native_sim.
Coverage
Measured with LCOV: CMock (unit_test_defconfig) vs. Ztest (Twister, native_sim).
numbers.ccrc32uncovered in bothtrig.ccmpx_cexpcoveragelut_trig.csofm_sine_lookup_16b